package com.hanfeng.client.view;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

public class MainActivity extends TabActivity {
	//声明一个TabHost对象
	public TabHost tabHost;
	//声明Activity
	public static final String TAB_HOME = "MusicListActivity";
	public static final String TAB_NET = "NetMusicActivity";
	public static final String TAB_LIKE = "LikeMusicActivity";
	//声明ImageButoon控件 本地音乐、网络音乐、喜欢音乐
	private ImageButton localButton,netButton,likeButton;	
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// 取消标题
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.tabhost_main);
		localButton = (ImageButton)findViewById(R.id.local_btn);
		netButton = (ImageButton)findViewById(R.id.net_btn);
		likeButton = (ImageButton)findViewById(R.id.grop_btn);
		
		//获取到TabHost
		tabHost = this.getTabHost();
		//添加本地音乐子页
		TabSpec tab_local = tabHost.newTabSpec(TAB_HOME).setIndicator(TAB_HOME);
		tab_local.setContent(new Intent(MainActivity.this,MusicListActivity.class));
		tabHost.addTab(tab_local);
		//添加在线音乐子页
		TabSpec tab_net = tabHost.newTabSpec(TAB_NET).setIndicator(TAB_NET);
		tab_net.setContent(new Intent(MainActivity.this,NetMusicActivity.class));
		tabHost.addTab(tab_net);
		//添加喜欢歌曲子页
		TabSpec tab_like = tabHost.newTabSpec(TAB_LIKE).setIndicator(TAB_LIKE);
		tab_like.setContent(new Intent(MainActivity.this,LikeMusicActivity.class));
		tabHost.addTab(tab_like);
		//绑定按钮监听
		localButton.setOnClickListener(new mainImageButtonClick());	
		netButton.setOnClickListener(new mainImageButtonClick());
		likeButton.setOnClickListener(new mainImageButtonClick());
		//显示选项卡内容
		tabHost.setCurrentTab(1);
		//设置默认选项卡
		localButton.setSelected(true);
	}
	
		//图片按钮监听
	public class mainImageButtonClick implements OnClickListener{

		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.local_btn:
				tabHost.setCurrentTabByTag(TAB_HOME);//设置要显示的页面
				localButton.setSelected(true);
				netButton.setSelected(false);
				likeButton.setSelected(false);
				break;
			case R.id.net_btn:
				tabHost.setCurrentTabByTag(TAB_NET);//设置要显示的页面
				localButton.setSelected(false);
				netButton.setSelected(true);
				likeButton.setSelected(false);
				break;
			case R.id.grop_btn:
				tabHost.setCurrentTabByTag(TAB_LIKE);//设置要显示的页面
				localButton.setSelected(false);
				netButton.setSelected(false);
				likeButton.setSelected(true);
				break;
			}
			
		}
		
	}
}
